/////////////////////////////////////////////////////////////////////////////
// Name:        message_sync_impl.h
// Purpose:
// Author:      syy
// Modified by:
// Created:     2015-03-11 17:09:59
// RCS-ID:
// Copyright:
// Licence:
/////////////////////////////////////////////////////////////////////////////
#ifndef _MESSAGE_SYNC_IMPL_H_
#define _MESSAGE_SYNC_IMPL_H_

#include <core/observer/message_observer.h>
#include <core/system/critical_section_wrapper.h>

#include <vector>

#include "../../include/message_sync.h"
#include "message_main_push.h"

namespace qb {
class CMessageSyncImpl : public IMessageSync {
 public:
  CMessageSyncImpl();
  virtual ~CMessageSyncImpl();

 public:
  STDMETHOD_(int32_t, Create)(THIS_);
  STDMETHOD_(int32_t, Destory)(THIS_);
  STDMETHOD_(int32_t, PushMessage)
  (THIS_ const char* buff, uint32_t bytes, uint32_t flag = 0, void* tag = NULL);
  STDMETHOD_(int32_t, RegisterMessageObserverTUS)
  (THIS_ IMessageSyncObserver* observer);
  STDMETHOD_(int32_t, DeRegisterMessageObserverTUS)
  (THIS_ IMessageSyncObserver* observer);
  STDMETHOD_(int32_t, RegisterMessageObserverTS)
  (THIS_ IMessageSyncObserver* observer);
  STDMETHOD_(int32_t, DeRegisterMessageObserverTS)
  (THIS_ IMessageSyncObserver* observer);
  STDMETHOD_(int32_t, RegisterMessageDispatchObserver)
  (THIS_ IMessageDispatchObserver* observer);
  STDMETHOD_(int32_t, DeRegisterMessageDispatchObserver)
  (THIS_ IMessageDispatchObserver* observer);
  STDMETHOD_(int32_t, DispatchMessage)
  (const char* buff, uint32_t bytes, uint32_t flag, void* tag);

 private:
  Atomic32 m_exit_flag;
  BList<IMessageSyncObserver*> m_observersTS;
  BList<IMessageSyncObserver*> m_observersTUS;
  IMessageDispatchObserver* m_observerDipatch;
  CriticalSectionWrapper& m_critSect;
  MessagePusher* m_pusher = nullptr;
};
}  // namespace qb

#endif  // _MESSAGE_SYNC_IMPL_H_
